import util from '../../utils/util'
import {
  GetGovern,
  GetGovernDetail
} from '../../config/api'

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    limit:1000,
    page:1,
    //active: 0,//当前激活选中项，默认为0
    gov_id:'',
    columns: [],
    notice_list:[], // 列表数组
  },
  /**
   * 跳转到详情页面
   */
  ToMessageDetail: function(e) {
    let item = e.currentTarget.dataset['item'];
    console.log("点击事件传递的参数：", item);
    wx.navigateTo({
      url: '/pages/newsDetail/newsDetail?id=' + item.id
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // console.log('公告公开type',options.type)
    let that = this;
    util.apiRequest(GetGovern, {
        type: 2,
        vollege_id:app.globalData.vollege_id
    }, null).then(r => {
      console.log('公告栏目', r);
      that.setData({
        columns: r.data.data,
        gov_id:r.data.data[0].id
      });
      that.getNoticeList();
    });
  },

  getNoticeList() {
    console.log('gov_id', this.data.gov_id)
    let that = this;
    let params = {
      gov_id: this.data.gov_id,
      page: this.data.page,
      limit: this.data.limit,
      vollege_id:app.globalData.vollege_id
    }
    util.apiRequest(GetGovernDetail, params, null).then(r => {
      console.log('11', r)
      that.setData({
        notice_list: r.data.data.data
      })
    })
  },

  SwitchStatus: function (e) {
    // 传递的参数
    let id = e.currentTarget.dataset.id;
    // console.log('点击事件传递的参数：',index);
    let that = this;
    that.setData({
      active: id,
      gov_id:id,
    });
    this.getNoticeList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
